{include file="public/header" /}
<div class="layui-col-lg5 layui-col-sm8">
    <form class="layui-form" onsubmit="return false" style="margin-top: 10px;">
        <div class="layui-form-item">
            <label for="files" class="layui-form-label">选择文件</label>
            <div class="layui-input-block">
                <input id="files" type="file" required multiple class="layui-input"
                       accept=".docx,.doc,.jpg,.png,.pdf,.tif">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label for="describe" class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea id="describe" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" onclick="submitFile()">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    function submitFile(){
        //文件列表
        var files = $("#files")[0].files;
        if(files.length < 1)
        {
            layer.msg('至少选择一个文件',{icon:0,time:2000});
            return false;
        }
        if(files.length >20 )
        {
            layer.msg('太多啦,选择20个以内',{icon:0,time:2000});
            return false;
        }
        var fileAry = new FormData();
        for(var i =0;i<files.length;i++)
        {
            fileAry.append('file[]',files[i]);
        }
        fileAry.append('describe',$("#describe").val());

        layer.msg('正在上传...',{icon:6,time:5000});
        $.ajax({
            url:'{:url("index/Order/upOrderFiles",["order_id"=>$order_id])}',
            type: "POST",
            data: fileAry,
            contentType: false,
            processData: false,
            success:function (data) {
                try{
                    data = JSON.parse(data);
                    if(data.state==200)
                    {
                        layer.msg(data.msg+'共上传'+data.count+'个,成功'+data.yes+'个,失败'+data.no+'个',
                            {icon:1,time:3000},function () {
                                window.location.reload();
                                return;
                            });
                    }
                    if(data.state==400)
                    {
                        layer.msg(data.msg,{icon:0,time:2000});
                        return;
                    }
                }catch (e) {
                    layer.msg('网络异常,稍后再试',{icon:0,time:2000});
                    return;
                }
            },error:function (data) {
                layer.msg('网络异常,稍后再试',{icon:0,time:2000});
                return;
            }
        })
    }
</script>